﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using DotSpatial.Topology.KDTree;

namespace HAMath
{
    public class Kriging
    {
        public Kriging(List<KrigingPoint> Pts)
        {
            this.Points = Pts;
            this.Tree = this.ConstructKdTree(Pts);
        }

        private List<KrigingPoint> _points;  //离散点，给定所有点坐标       

        /// <summary>
        /// 离散点，给定所有点坐标
        /// </summary>
        public List<KrigingPoint> Points
        {
            get { return _points; }
            set { _points = value; }
        }


        DotSpatial.Topology.KDTree.KdTree _tree;  //Kd树，用来查找邻近点

        /// <summary>
        /// Kd树，用来查找邻近点
        /// </summary>
        public DotSpatial.Topology.KDTree.KdTree Tree
        {
            get { return _tree; }
            set { _tree = value; }
        }


        private KrigingType _krigType = KrigingType.Ordinary;

        public KrigingType KrigType
        {
            get { return _krigType; }
            set { _krigType = value; }
        }


        private SearchOption _searchOption = new SearchOption();     //搜索选项

        /// <summary>
        /// 搜索选项
        /// </summary>
        public SearchOption SearchOption
        {
            get { return _searchOption; }
            set { _searchOption = value; }
        }

        private SearchEllipsoid _ellipsoid = new SearchEllipsoid();  //搜索范围

        /// <summary>
        /// 模型变差函数
        /// </summary>
        public SearchEllipsoid Ellipsoid
        {
            get { return _ellipsoid; }
            set { _ellipsoid = value; }
        }

        private ModelVariogram _model = new ModelVariogram(ModelType.Exponential, 1000, 0, 83);  //模型变差函数

        /// <summary>
        /// 模型变差函数
        /// </summary>
        public ModelVariogram Model
        {
            get { return _model; }
            set { _model = value; }
        }



        /// <summary>
        /// 构造KdTree
        /// </summary>
        protected DotSpatial.Topology.KDTree.KdTree ConstructKdTree(List<KrigingPoint> pts)
        {
            DotSpatial.Topology.KDTree.KdTree tree = new KdTree(2);
            foreach (KrigingPoint pt in this.Points)
            {
                double[] xy = new double[2];
                xy[0] = pt.X;
                xy[1] = pt.Y;
                tree.Insert(xy, pt);
            }

            return tree;
        }

    }
}
